;:poke56,28000/256:clr
;:sys36864
	;.opt oo
	*= 28000
v	=53248
tmp	=2
tmp2	=4
konf	=1
neuzeich	=$e000
bank	=$dd00
screen	=648
cint	=65409
neupos	=8*64
neuze	=neuzeich+neupos
tmp3	=166
scrn	=$c400
screenfld	=scrn+41
feld	=$8000 	; auch schon (anzspal) bytes davor belegt   high = 0 !!
farbram	=$d800
dst3	=34
spalt	=211
print	=$ffd2
sprpt1	=2040+49152
sprit1	=2048+49152
sprit2	=2112+49152
sprit3	=2176+49152
irqvec	=$314
oldirq	=$ea31
key	=198
joyst	=56320
get	=65508
delay	=10
tab40l	=$c000
tab40h	=$c080
tabxxl	=$c100
tabxxh	=$c180
sprixh	=>272
sprixl	=<272
raster	=v+18
s	=$d400
xtab	=$ca00
ytab	=$cb00
skopie	=$c200
bildx	=$e9f0
bild	=$d1
dumm	=120 	; wahrscheinlichk. fuer uebersehen eines angriffs
sidrnd	=s+27
erfolg	=$8300 	; ab $8300 x-koor
;             	; ab $8700 y-koor
;             	; ab $8b00 horz/vert
reset	=$fffc
tmp4	=139
rept	=650
mtr1	=$dc00
mtr2	=mtr1+1
	jmp start
seg	.byt $7e,$66,$66,$7e,$66,$66,$7e,0
mat2	.byt 0,0,$24,24,24,$24,0,0
mat1	.byt 0,0,60,36,36,60,0,0
chars	.byt 124,60,66,$99,$a1,$a1,$99,66,60
	.byt 106,99,51,91,111,103,99,99,0
	.byt 116,99,99,99,111,99,99,99,0
	.byt 176,126,102,102,102,102,102,126,0
	.byt 177,6,6,6,6,6,6,6,0
	.byt 178,126,6,6,126,96,96,126,0
	.byt 179,126,6,6,126,6,6,126,0
	.byt 180,102,102,102,126,6,6,6,0
	.byt 181,126,96,96,126,6,6,126,0
	.byt 182,126,96,96,126,102,102,126,0
	.byt 183,126,6,6,6,6,6,6,0
	.byt 184,126,102,102,126,102,102,126,0
	.byt 185,126,102,102,126,6,6,126,0
	.byt 30,127,54,54,54,54,54,127,0
	.byt 40,0,8,24,63,63,24,8,0
	.byt 41,0,16,24,252,252,24,16,0
	.byt 168,231,231,199,231,231,231,129,255
	.byt 169,195,153,249,227,249,153,195,255
	.byt 31,127,42,42,42,42,42,127,0
	.byt 92,0,0,0,255,255,0,0,0
	.byt 28,255,81,81,74,74,68,255,0
	.byt 167,129,159,131,249,249,153,195,255
	.byt 156,129,153,243,231,231,231,231,255
	brk
coltab	.byt 0,11,12,15,1,15,12,11
log	.byt 100,10,1
won	.byt %00011111,%00111111
anzbit	.byt 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4
grbit	.byt 1,2,4,8
drantab	.byte "12?"
valid	brk
copa	brk
copy	brk
copx	brk
feldtask	brk
mouseflg	brk
mousevh	brk
mousex	brk
mousey	brk
colnr	brk
colflg	brk
old16	brk
sc1	.word 0
sc2	.word 0
zahl	brk
dran	brk
xmerk	=181   	; 1 byte
ymerk	=182   	; 1  ""
samen	=141   	; 1  ""
index	=142   	; 1  ""
minimum	=143 	; 1  ""
beep	brk
ergy	=251    	; 1  ""
ergx	=252    	; 1  ""
ergvh	=253   	; 1  ""
doagain	brk
gegner1	brk
gegner2	brk
joy	brk
joynr	brk
strenght	=254	; 1  ""
wahl	    =255	; 1  ""
lfdnr	   =178	; 1  ""
lfdbit	  =179	; 1  ""
wahl2	   =183	; 1  ""
ergx2	   =187	; 1  ""
ergy2	   =188	; 1  ""
soviel	  =97 	; 2  ""
sovrek	  =99 	; 2  ""
nochwas	 =101	; 1  ""
irqbeweis	brk
jokflag	brk
anzhi	brk
azzei	.byt 22
azzei1	.byt 23
azzeim1	.byt 21
azspa	.byt 23
azspa1	.byt 24
azspam1	.byt 22
mult	.word 22*23
blinkcnt	.byt 1
blinktst	brk
pstack	brk
mensch	brk
hitxt	.byte "\x93\x11\x11\x99\x08\x18kaesekaestchen\x1a\x18v1.2 \xaa\xb4 100588\x1a\x18\x1d"
	.byte "\xbc n. heusler\x1a\x19\x10}\x11\x18\x1esp 1: \x99   \x05 W\x1a\x18\x1esp 2: \x99   \x05 V\x03"
wgw	.byte "\x1a\x13\x19\x06\x11\x05\x18wer gegen wen ?\x1a\x18\x12f(/f)\x92 = wahl"
	.byte "\x1a\x18\x12f'\x92    = hind.\x1a\x18\x12f\\x92    = feld"
	.byte "\x1a\x18\x12retrn\x92 = okay\x1a\x11\x11\x18  W      V"
	.byte "\x1a\x19\x05\x11\x18\x98spieler \xa6\x03"
geg0	.byte "\x1a\x13\x19"
	.byt 13
	.byte "\x11\x96\x18\x03"
geg1	.byte "port1"
	.byte "port2"
	.byte "c64 i"
	.byte "c64 ^"
	.byte "c64 _"
	.byte "c64 \"
hindy	.byte "\x11\x11\x1a\x18\x96  \x9ehindernisse\x03"
wontxt	.byte "\x1a\x13\x19\x08\x11\x9e\x18\x03"
wonplr	.byte "gewonnen hat\x1a\x18spieler \x03"
wonune	.byte "es steht un-\x1a\x18entschieden\x03"
revanche	.byte "\x1a\x1a\x18noch ein spiel\x1a\x18 [j/n] ??\x03"
help	.byte "\x1a\x13\x19\x07\x11\x96\x18steuerung:\x1a\x18\x12clr\x92 = zuganz.\x1a\x18\x12joyst.\x92"
	.byte " = ort\x1a\x18\x12feuer\x92  = \xdd()\xdc\x1a\x18\x12return\x92 = zug\x1a\x18\x12stop"
	.byte "\x92   = abbr.\x1a\x18\x12?\x92 = vorschlag\x1a\x18\x12inst\x92 = joker\x03"
core1	.byte "\x13\x19\x11\x11\x18\x05computer\x1a\x18rechnet\x03"
core0	.byte "\x13\x19\x11\x11\x18\x19\x08 \x1a\x18\x19\x07 \x03"
hintab	.word hd0,hd1,hd2,hd3,hd4,hd5,hd6,hd7
hd1	.byt 0,12,16,14,1,12,16,14
hd0	.byt -1
hd2	.byt 0,4,8,4,1,4,8,4
	.byt 0,15,20,16,1,13,18,17,-1
hd3	.byt 1,6,17,20,1,6,17,10,1,6,17,3,-1
hd4	.byt 0,12,16,14,1,12,16,14
	.byt 0,2,6,14,1,12,16,4
	.byt 0,7,11,11,1,9,13,9
	.byt 0,7,11,18,1,16,20,9,-1
hd5	.byt 1,6,17,11
	.byt 0,7,11,11,1,9,13,99
	.byt 0,4,8,8,1,4,8,4
	.byt 0,13,15,17,0,13,15,19,1,17,19,13,1,17,19,15
	.byt 0,5,9,1,1,1,3,9,0,9,12,3,1,1,3,12,-1
hd6	.byt 0,17,21,6,0,17,21,12,1,6,12,17,1,6,12,21
	.byt 0,11,16,9,1,6,11,13
	.byt 0,12,16,14,1,12,16,14
	.byt 0,3,7,13,1,11,15,5
	.byt 1,14,20,2,0,2,17,20,1,17,20,17
	.byt 0,4,8,8,1,4,8,4,-1
hd7	.byt 0,8,10,14,1,10,14,10
	.byt 0,4,10,14,1,9,14,4
	.byt 0,13,15,17,0,13,15,19,1,17,19,13,1,17,19,15
	.byt 1,18,22,4,0,1,5,18
	.byt 0,17,21,4,1,2,6,19
	.byt 0,15,20,16,1,13,18,17
	.byt 1,0,6,6,0,0,6,6
	.byt 0,17,20,7,0,17,20,10,1,7,10,17,1,7,10,20,-1
zsatz	sei
	lda #51
	sta konf
	ldy #0
	sty tmp
	sty tmp2
	lda #>v
	sta tmp+1
	lda #>neuzeich
	sta tmp2+1
	ldx #8
zcopy	lda (tmp),y
	sta (tmp2),y
	dey
	bne zcopy
	inc tmp+1
	inc tmp2+1
	dex
	bpl zcopy
	jsr kram
	lda #148
	sta bank
	lda #>scrn
	sta screen
	lda #24
	sta v+24
	inx
	stx v+32
	stx v+33
	stx mouseflg
	inx
	stx v+29
	stx v+23
	inx
	stx v+27
	lda #34
	sta sprpt1+1
	lda #11
	sta v+40
	lda #217
	sta v+3
	lda #sprixl
	sta v+2
	lda #sprixh*2
	sta v+16
	jsr setptr
	ldx #7
no0	lda #0
	ldy #7
lp3	sta (tmp),y
	dey
	bpl lp3
	jsr tp8
	lda #128
	sta rept
	ldy #7
lp1	sta (tmp),y
	dey
	bpl lp1
	jsr tp8
	dex
	bpl no0
	jsr setptr
	ldy #0
	ldx #3
lp2	jsr tp8
	jsr tp8
	lda #255
	sta (tmp),y
	jsr tp8
	lda #255
	sta (tmp),y
	jsr tp8
	dex
	bpl lp2
	jsr setptr
	ldx #1
lp4	jsr tp32
	ldy #31
lp5	lda (tmp),y
	ora #1
	sta (tmp),y
	dey
	bpl lp5
	jsr tp32
	dex
	bpl lp4
	jsr setptr
	jsr tp32
	jsr tp32
	ldx #7
	ldy #7
lp6	lda #255
	sta (tmp),y
	jsr tp8
	dex
	bpl lp6
	jsr setptr
	lda tmp
	sta tmp3
	clc
	adc #128
	sta tmp2
	lda tmp+1
	adc #0
	sta tmp2+1
	lda tmp+1
	clc
	adc #1
	sta tmp3+1
	ldy #127
lpx	lda (tmp),y
	sta (tmp2),y
	sta (tmp3),y
	dey
	cpy #119
	bcs lpx
	ldy #127
	ldx #7
lpy	lda (tmp2),y
	ora mat1,x
	sta (tmp2),y
	lda (tmp3),y
	ora mat2,x
	sta (tmp3),y
	dex
	bpl lpyy
	ldx #7
lpyy	dey
	cpy #119
	bcs lpy
	lda #<chars
	ldy #>chars
	jsr settmp
ch1	ldy #0
	sty tmp2+1
	lda (tmp),y
	beq ch2
	asl
	rol tmp2+1
	asl
	rol tmp2+1
	asl
	rol tmp2+1
	sta tmp2
	lda tmp2+1
	clc
	adc #>neuzeich
	sta tmp2+1
	ldy #7
	inc tmp
	bcc ch3
	inc tmp+1
ch3	lda (tmp),y
	sta (tmp2),y
	dey
	bpl ch3
	jsr tp8
	jmp ch1
ch2	lda #0
	ldx #192
delspr	sta sprit1,x
	dex
	cpx #-1
	bne delspr
	lda #31
	sta sprit1+1
	sta sprit1+4
	lda #3
	ldx #4
	ldy #0
sts	sta sprit2,y
	iny
	iny
	iny
	dex
	bpl sts
	ldx #7
	ldy #0
setlp	lda seg,x
	sta sprit3,y
	sta sprit3+1,y
	sta sprit3+2,y
	sta sprit3+24,y
	sta sprit3+25,y
	sta sprit3+26,y
	iny
	iny
	iny
	dex
	bpl setlp
	jsr krom
	cli
	rts
tpxx	lda azspa
	.byt $2c
tp3	lda #3
	.byt $2c
tp40	lda #40
	.byt $2c
tp8	lda #8
	.byt $2c
tp32	lda #32
	sta tpx+4
tpx	lda tmp
	clc
	adc #0
	sta tmp
	bcc rt
	inc tmp+1
rt	rts
clrline	jsr bildx
	ldy #39
	lda #32
cll1	sta (bild),y
	dey
	cpy azspa1
	bcs cll1
	rts
clrmenue	ldx #5
clrm	jsr clrline
	inx
	cpx #20
	bcc clrm
	rts
calcchr	pha
	and #16
	beq noletter
	pla
	and #32
	beq null
	lda #47
	rts
null	lda #31
	rts
noletter	pla
	and #15
	rts
setptr	lda #<neuze
	ldy #>neuze
settmp	sta tmp
	sty tmp+1
	rts
feldtmp	lda #<feld
	ldy #>feld
	bne settmp
random	lda raster
	ror
	sbc samen
	eor sidrnd
	eor #$aa
	rol
	adc sidrnd
	eor samen
	adc raster
	sta samen
	rts
co1	lda #<core1
	ldy #>core1
	jmp strout
co0	lda #<core0
	ldy #>core0
	jmp strout
kram	lda #53
	.byt $2c
krom	lda #55
	sta konf
	rts
color	lda tmp2+1
	and #3
	ora #>farbram
	sta tmp3+1
	lda tmp2
	sta tmp3
	rts
seterf	lda #<erfolg
	ldy #>erfolg
	sta tmp2
	sty tmp2+1
	rts
trans	lda tmp2
	sta tmp3
	lda tmp2+1
	sta tmp3+1
	rts
switch	clc
	lda tmp3+1
	adc #4
	sta tmp3+1
	rts
initfield	jsr cdst3
	ldy #0
	tya
ifi	sta feld,y
	sta feld+$100,y
	dey
	bne ifi
	ldy azspam1
	dey
	dey
set2	lda #2
	iny
	sta feld,y
	lda #8
	sta (dst3),y
	dey
	dey
	bpl set2
	ldx azzeim1
	dex
	dex
	jsr feldtmp
zeile2	jsr tpxx
	ldy #0
	lda #1
	sta (tmp),y
	ldy azspam1
	lda #4
	sta (tmp),y
	dex
	bpl zeile2
	lda #3
	sta feld
	lda #6
	ldy azspam1
	sta feld,y
	lda #12
	sta (dst3),y
	lda #9
	ldy #0
	sta (dst3),y
	rts
strout	sta tmp
	sty tmp+1
st	ldy #0
	lda (tmp),y
	cmp #"\x03"
	bne goon
	rts
goon	cmp #"\x1a"
	bne nocr
	lda #13
nocr	cmp #"\x18"
	bne noiks
	lda #25
	sta spalt
wt	inc tmp
	bne st
	inc tmp+1
	bne st
noiks	cmp #"\x19"
	beq rep
	jsr print
	bcc wt
rep	iny
	lda (tmp),y
	tax
	iny
	lda (tmp),y
repp	jsr print
	dex
	bne repp
	jsr tp3
	bcc st
gett	ldy #0
	lda (tmp4),y
	inc tmp4
	bne itr
	inc tmp4+1
itr	rts
mask	lda #<hitxt
	ldy #>hitxt
	jsr strout
	inc feldtask
	rts
clrsid	ldx #0
	txa
csi	sta s,x
	dex
	bpl csi
	lda #15+128
	sta s+24
	lda #100
	sta s+1
	sta s+15
	lda #129
	sta s+18
	lda #9
	sta s+5
	lda #240
	sta s+6
	rts
ofield	lda tmp2
	pha
	lda tmp2+1
	pha
	lda tmp3
	pha
	lda tmp3+1
	pha
	lda #<screenfld
	ldy #>screenfld
	sta tmp2
	sty tmp2+1
	jsr color
	jsr feldtmp
	ldx azzei
zeile	ldy azspam1
spalte	lda (tmp),y
	jsr calcchr
	ora #64
	sta (tmp2),y
	lda #14
	sta (tmp3),y
	dey
	bpl spalte
	jsr tpxx
	lda tmp2
	clc
	adc #40
	sta tmp2
	bcc nope2
	inc tmp2+1
nope2	jsr color
	dex
	bne zeile
	pla
	sta tmp3+1
	pla
	sta tmp3
	pla
	sta tmp2+1
	pla
	sta tmp2
	rts
cdst3	lda mult
	sec
	sbc azspa
	sta dst3
	lda mult+1
	sbc #0
	sta dst3+1
	clc
	lda dst3+1
	adc #>feld
	sta dst3+1
	rts
irqinit	sei
	lda #<neuirq
	ldy #>neuirq
	sta irqvec
	sty irqvec+1
	lda #0
	sta feldtask
	sta colnr
	sta mouseflg
	sta mousevh
	sta mousex
	sta mousey
	sta jokflag
	sta beep
	sta blinktst
	ldx #3
set0	sta sc1,x
	dex
	bpl set0
	lda #2
	sta dran
	lda #40
	sta dudel+1
	cli
nofeld	rts
neuirq	lda tmp
	pha
	lda tmp+1
	pha
	jsr feld10
	jsr domouse
	jsr zahlout
	jsr peep
	ldx joynr
	lda joyst,x
	sta joy
	ldx dran
	lda drantab,x
	sta scrn+833
	inc irqbeweis
	jsr blinkfd
	pla
	sta tmp+1
	pla
	sta tmp
	jmp oldirq
feld10	lda feldtask
	beq nofeld
	lda #0
	sta feldtask
	jmp ofield
blinkfd	lda blinktst
	bne flashing
	lda farbram+433
	beq blink
	rts
blink	ldx #3
blinnk	lda farbram+433,x
	eor #1
	sta farbram+433,x
	dex
	bpl blinnk
	rts
flashing	dec blinkcnt
	bne nofeld
	lda #15
	sta blinkcnt
	bne blink
domouse	lda mouseflg
	bne mousean
	lda #2
	sta v+21
	rts
mousean	lda #3
	sta v+21
	lda v+27
	eor #1
	sta v+27
	lda mousevh
	bne vertikal
	lda mousex
	asl
	asl
	asl
	adc #9
	tax
	lda mousey
	asl
	asl
	asl
	adc #56
	ldy #32
	bne setmouse
vertikal	ldy #33
	lda mousex
	asl
	asl
	asl
	adc #18
	tax
	lda mousey
	asl
	asl
	asl
	adc #57
setmouse	sty sprpt1
	stx v
	sta v+1
	lda colflg
	eor #128
	sta colflg
	bmi nochg
	ldx colnr
	dex
	bpl actcol
	ldx #7
actcol	stx colnr
	lda coltab,x
	sta v+39
nochg	rts
zahlout	ldx #103
	lda sc1
	ldy sc1+1
	jsr numeric
	ldx #143
	ldy sc2+1
	lda sc2
numeric	jsr settmp
	ldy #0
nu3	lda #176
	sta zahl
nu1	tya
	bne nu4
	lda tmp+1
	beq nu4
	lda tmp
	sec
	sbc #100
	sta tmp
	lda tmp+1
	sbc #0
	sta tmp+1
	inc zahl
	bne nu1
nu4	lda tmp
	cmp log,y
	bcc nu2
	lda tmp
	sbc log,y
	sta tmp
	inc zahl
	bne nu1
nu2	lda zahl
	sta scrn+$300,x
	inx
	iny
	cpy #3
	bcc nu3
	rts
wartirq	cli
	lda irqbeweis
	cmp irqbeweis
	beq wartirq
	rts
peep	lda beep
	beq nopeep
	dec beep
	lda #33
	sta s+4
	jsr dudel
	jsr dudel
	lda #32
	sta s+4
	jsr dudel
	lda #33
	sta s+4
	jsr dudel
	jsr dudel
	lda #32
	sta s+4
dudel	ldx #40
	ldy #0
steffi	dey
	bne steffi
	dex
	bne steffi
nopeep	rts
gtkoor	lda #0
	sta jokflag
	inc mouseflg
	inc feldtask 	; eigentl. unnoetig
	lda #0
	sta key
schleife	ldy #delay
	ldx #0
del	jsr t162
	dex
	bne del
	dey
	bne del
	lda key
	bne tasted
	lda joy
	and #31
	cmp #31
	beq schleife
	and #1
	bne nodir1
	lda mousey
	beq nodir1a
	dec mousey
nodir1	lda joy
	and #2
	bne nodir2
	lda mousey
	cmp azzeim1
	bcs nodir2a
	inc mousey
nodir2	lda joy
	and #4
	bne nodir4
	lda mousex
	beq nodir4a
	dec mousex
nodir4	lda joy
	and #8
	bne nodir8
	lda mousex
	cmp azspam1
	bcs nodir8a
	inc mousex
nodir8	jsr t16
	lda joy
	and #16
	bne schleife
	lda mousevh
	eor #1
	sta mousevh
tasted	jsr get
	beq qschleife
	cmp #13
	bne hmt
	jsr test
	bne qschleife
	clc
	bcc rumaus
hmt	cmp #"\x13"
	bne stoped
	jsr blick
	jmp qschleife
stoped	cmp #"?"
	beq helpme
	cmp #20
	beq joker
	cmp #"\x03"
	bne qschleife
rumaus	lda #0
	sta mouseflg
	rts
nodir1a	lda azzeim1
	.byt $2c
nodir2a	lda #0
	sta mousey
	jmp nodir2
nodir4a	lda azspam1
	.byt $2c
nodir8a	lda #0
	sta mousex
	jmp nodir8
t16	lda joy
	and #16
	cmp old16
	bne keinsinn
	pla
	pla
qschleife	jmp schleife
helpme	lda #1
	rts
joker	dec jokflag
	clc
	rts
t162	lda joy
	and #16
	beq keinsin2
keinsinn	sta old16
keinsin2	rts
test	ldy mousey
	lda tab40l+1,y
	sta tmp
	lda tab40h+1,y
	ora #>scrn
	sta tmp+1
	ldy mousex
	iny
	lda (tmp),y
	ldx mousevh
	beq waage
	and #1
	rts
waage	and #2
	rts
blick	lda valid
	bne blickok
	rts
blickok	lda copx
	sta mousex
	lda copy
	sta mousey
	lda copa
	sta mousevh
	rts
makemath	php
	sei
	lda #0
	tax
	tay
	jsr settmp
	ldy azzei1
math1	lda tmp+1
	sta tab40h,x
	lda tmp
	sta tab40l,x
	jsr tp40
	inx
	dey
	bpl math1
	lda #0
	tax
	tay
	jsr settmp
	ldy azzei1
math2	lda tmp+1
	sta tabxxh,x
	lda tmp
	sta tabxxl,x
	jsr tpxx
	inx
	dey
	bpl math2
	plp
	rts
; setaxy setzt einen balken (a = 0 => waagerecht)
setaxy	sta copa
	stx copx
	sty copy
	pha
	lda #1
	sta valid
	lda tabxxh,y
	ora #>feld
	sta tmp+1
	lda tabxxl,y
	sta tmp
	txa
	tay
	pla
	beq wag
	lda (tmp),y
	ora #1
	sta (tmp),y
	dey
	lda #4
	bne saat
wag	lda (tmp),y
	ora #2
	sta (tmp),y
	lda tmp
	sec
	sbc azspa
	sta tmp
	lda tmp+1
	sbc #0
	sta tmp+1
	lda #8
saat	ora (tmp),y
	sta (tmp),y
	rts
testfull	lda #0
	sta doagain
	jsr feldtmp
	ldx azzeim1
xzeile	ldy azspam1
xspalte	lda (tmp),y
	cmp #15
	bne nee
	stx xmerk
	ldx dran
	lda won,x
	sta (tmp),y
	txa
	asl
	tax
	inc sc1,x
	bne nozwei
	inc sc1+1,x
nozwei	ldx xmerk
	inc doagain
nee	dey
	bpl xspalte
	jsr tpxx
	dex
	bpl xzeile
	rts
wergewon	lda sc1
	clc
	adc sc2
	sta tmp
	lda sc1+1
	adc sc2+1
	cmp mult+1
	bcc mussnoch
	bne hatschon
	lda tmp
	cmp mult
	bcc mussnoch
hatschon	lda sc1+1
	cmp sc2+1
	bcc win2
	bne win1
	lda sc1
	cmp sc2
	bcc win2
	bne win1
	lda #192
	rts
mussnoch	lda #0
	rts
win2	lda #127
	rts
win1	lda #64
	rts
save	ldy #0
save1	lda feld,y
	sta skopie,y
	lda feld+$100,y
	sta skopie+$100,y
	dey
	bne save1
	rts
load	ldy #0
load1	lda skopie,y
	sta feld,y
	lda skopie+$100,y
	sta feld+$100,y
	dey
	bne load1
	rts
intab	ldx index
	inc index
	bne rein
	dec index
rein	lda ymerk
	sta xtab,x
	lda xmerk
	sta ytab,x
	rts
; suche computerzug (ergx,ergy,ergvh)
szug	ldx #0
	stx index
	dex
	stx minimum
	jsr feldtmp
	ldx #0
szeile	stx xmerk
	ldy #0
sspalte	sty ymerk
	lda (tmp),y
	and #15
	tax
	lda anzbit,x
	cmp #4
	bcs ignore
	cmp #3
	bne defense
	lda strenght
	bne sagwas
	jsr random
	cmp #dumm
	bcc ignore
sagwas	lda ymerk
	sta xtab
	ldy xmerk
	ldx #0
	beq hates
defense	ldx strenght
	cpx #2
	bcs hinein
	cmp minimum
	beq nimm
	bcs ignore
	ldx #0
	stx index
nimm	sta minimum
hinein	jsr intab
ignore	ldy ymerk
	iny
	cpy azspa
	bcc sspalte
	jsr tpxx
	ldx xmerk
	inx
	cpx azzei
	bcc szeile
	lda strenght
	cmp #2
	bcs klar
	lda minimum
	cmp #4
	bcc klar
	jmp szug
klar	lda strenght
	cmp #2
	bcc suchzuf
	jmp suchbest
suchzuf	jsr random
	cmp index
	bcs suchzuf
	tax
	ldy ytab,x
hates	sty ergy
	lda tabxxl,y
	sta tmp
	lda tabxxh,y
	ora #>feld
	sta tmp+1
	ldy xtab,x
	sty ergx
	lda (tmp),y
	and #15
	sta wahl
vtd	jsr random
	and #3
	tax
	lda wahl
	and grbit,x
	bne vtd
	txa
	and #1
	eor #1
	sta ergvh
	cpx #2
	bcc zugok
	lda ergvh
	beq lieg
	inc ergx
	rts
lieg	inc ergy
zugok	rts
; bei welchem verteid.zug kann der gegner am wenigsten machen
suchbest	lda #-1
	sta sovrek
	sta sovrek+1
	ldx index
be1	dex
	stx lfdnr
	ldy ytab,x
	sty ergy2
	lda tabxxl,y
	sta tmp
	lda tabxxh,y
	ora #>feld
	sta tmp+1
	ldy xtab,x
	sty ergx2
	lda (tmp),y
	and #15
	sta wahl2
	ldx #1
be2	stx lfdbit
	lda wahl2
	and grbit,x
	bne be3
	jsr wieviel
	lda strenght
	cmp #3
	bcs be3
	lda sovrek
	bne be3
	lda sovrek+1
	bne be3
	lda #<erfolg
	sta tmp3
	lda #>erfolg
	sta tmp3+1
	bne be7
be3	ldx lfdbit
	dex
	bpl be2
	ldx lfdnr
	bne be1
be4	jsr random
	sta tmp3
	jsr random
	and #3
	clc
	adc #>erfolg
	sta tmp3+1
	lda tmp3+1
	cmp tmp2+1
	bcc be7
	bne be4
	lda tmp3
	cmp tmp2
	bcs be4
be7	ldy #0
	lda (tmp3),y
	sta ergx
	jsr switch
	lda (tmp3),y
	sta ergy
	jsr switch
	lda (tmp3),y
	eor #1
	and #1
	sta ergvh
	rts
; wieviele karos kann der gegner setzen, wenn ich das mache
wieviel	jsr save
	jsr abbruch
	ldx ergx2
	ldy ergy2
	lda lfdbit
	eor #1
	jsr setaxy
	lda #0
	sta soviel
	sta soviel+1
	jsr suchkaro
	jsr load
	lda soviel+1
	cmp sovrek+1
	bcc neuer
	bne in2
	lda soviel
	cmp sovrek
	beq take
	bcs in2
neuer	jsr seterf
	lda soviel
	sta sovrek
	lda soviel+1
	sta sovrek+1
take	ldy #0
	lda ergx2
	sta (tmp2),y
	jsr trans
	jsr switch
	lda ergy2
	sta (tmp3),y
	jsr switch
	lda lfdbit
	sta (tmp3),y
	inc tmp2
	bne in2
	inc tmp2+1
in2	rts
abbruch	lda #127
	sta mtr1
	cmp mtr2
	beq aus
	rts
aus	ldx pstack
	txs
	cli
	jsr co0
	lda mensch
	beq compi
	jmp user
compi	jmp abort
; high-speed routine folgt
; gibt es karos zu setzen in dieser situtaion
suchkaro	lda #<feld
	ldy #>feld
	sta tmp4
	sty tmp4+1
	ldx #0
	stx nochwas
szeil	stx xmerk
	ldy #0
sspal	sty ymerk
	lda (tmp4),y
	and #15
	sta wahl
	tax
	lda anzbit,x
	cmp #3
	bne ignor
	sta nochwas
	sty ergx
	ldy xmerk
	ldx #4
vttd	dex
	lda wahl
	and grbit,x
	bne vttd
	txa
	eor #1
	and #1
	cpx #2
	bcc zugokok
	tax
	beq lieeg
	inc ergx
	bne zugokok
lieeg	iny
zugokok	ldx ergx
	jsr setaxy
	inc soviel
	bne ignor
	inc soviel+1
ignor0	ldy ymerk
ignor	iny
	cpy azspa
	bcc sspal
	lda tmp4
	adc azspam1
	sta tmp4
	bcc noi4
	inc tmp4+1
noi4	ldx xmerk
	inx
	cpx azzei
	bcc szeil
	lda nochwas
	bne suchkaro
	rts
start	jsr cint
	jsr makemath
	jsr zsatz
	jsr initfield
	jsr irqinit
	jsr mask
	jsr clrsid
	lda #3
	sta strenght
	lda #<wgw
	ldy #>wgw
	jsr strout
wa1	lda #<geg0
	ldy #>geg0
	jsr strout
	lda gegner1
	asl
	asl
	adc gegner1
	tay
	ldx #4
wa2	lda geg1,y
	jsr print
	iny
	dex
	bpl wa2
	lda #"("
	jsr print
	lda #")"
	jsr print
	lda gegner2
	asl
	asl
	adc gegner2
	tay
	ldx #4
wa3	lda geg1,y
	jsr print
	iny
	dex
	bpl wa3
	lda #<hindy
	ldy #>hindy
	jsr strout
	lda anzhi
	ora #48
	sta scrn+665
	cmp #49
	bne waa4
	lda #0
	sta farbram+677
	sta farbram+676
waa4	lda #0
	sta key
wa4	jsr get
	cmp #13
	beq chosen
	cmp #"\x85"
	beq wa5
	cmp #"\x86"
	bne wa6
	inc gegner2
	lda gegner2
	cmp #6
	bcc wa1
	lda #0
	sta gegner2
	beq wa1
wa5	inc gegner1
	lda gegner1
	cmp #6
	bcc qwa1
	lda #0
	sta gegner1
	beq qwa1
wa6	cmp #"\x87"
	bne wa9
	inc anzhi
	lda anzhi
	cmp #8
	bcc qwa1
	lda #0
	sta anzhi
qwa1	jmp wa1
wa9	cmp #"\x88"
	bne wa4
	inc blinktst
grlp	lda joyst
	and joyst+1
	tax
	and #16
	bne more
freig	dec blinktst
	jmp wa1
more	txa
	and #1
	beq upfd
	txa
	and #2
	beq dofd
	txa
	and #4
	beq qlifd
	txa
	and #8
	beq refd
	jsr get
	cmp #"\x03"
	beq freig
	cmp #13
	beq freig
	bne grlp
qlifd	beq lifd
chosen	jsr clrmenue
	jsr behindern
	ldx #1
	stx dran
	dex
	stx valid
	jmp nexter
upfd	lda azzei
	cmp #4
	bcs good
outof	jmp grlp
good	dec azzei
param	php
	sei
	ldx azzei
	inx
	stx azzei1
	dex
	dex
	stx azzeim1
	ldy azspa
	dey
	sty azspam1
	iny
	iny
	sty azspa1
	lda #0
	sta tmp
	sta tmp+1
mamu	jsr tpxx
	dex
	bpl mamu
	lda tmp
	sta mult
	lda tmp+1
	sta mult+1
	jsr makemath
	jsr clrbfe
	jsr initfield
	plp
	inc feldtask
	jmp outof
dofd	lda azzei
	cmp #22
	bcs outof
	inc azzei
	bne param
refd	lda azspa
	cmp #23
	bcs outof
	inc azspa
	bne param
lifd	lda azspa
	cmp #4
	bcc outof
	dec azspa
	bne param
clrbfe	ldx #0
	ldy azspa1
cllrp	jsr bildx
	lda #" "
	sta (bild),y
	inx
	cpx azzei1
	bcc cllrp
	jsr bildx
	ldy #0
	lda #32
clrrp	sta (bild),y
	iny
	cpy azspa1
	bcc clrrp
	rts
nexter	lda dran
	eor #1
	sta dran
	jsr wartirq
affe	jsr ziehen
	bit jokflag
	bmi mogel
	jsr setaxy
	jmp ehrlich
mogel	lda #0
	sta mouseflg
	jsr signal
	inc jokflag
	beq noton
ehrlich	jsr testfull
	lda doagain
	bne noton
	inc beep
noton	lda #1
	sta feldtask
	jsr wartirq
	jsr wergewon
	bne finish
	lda doagain
	bne affe
	beq nexter
finish	pha
	inc feldtask
	lda #<wontxt
	ldy #>wontxt
	jsr strout
	pla
	bpl einer
	lda #<wonune
	ldy #>wonune
	jsr strout
	jmp feddisch
einer	pha
	lda #<wonplr
	ldy #>wonplr
	jsr strout
	pla
	cmp #64
	bne zweiwon
	lda #"1"
	.byt $2c
zweiwon	lda #"2"
	jsr print
feddisch	lda #<revanche
	ldy #>revanche
	jsr strout
	lda #0
	sta key
gjn	jsr get
	cmp #"n"
	bne non
	jmp (reset)
non	cmp #"j"
	bne gjn
	jmp start
ziehen	ldx dran
	ldy gegner1,x
	bne kl1
	lda #1
	bne setjoy
kl1	cpy #1
	bne no1
	lda #0
setjoy	sta joynr
	lda #<help
	ldy #>help
	jsr strout
user	jsr gtkoor
	bcc trau
	tax
	beq qabort
	jsr co1
	lda #1
	sta mensch
	sei
	tsx
	stx pstack
	jsr szug
	jsr co0
	lda #0
	sta valid
	ldx ergx
	ldy ergy
	lda ergvh
	stx mousex
	sty mousey
	sta mousevh
	bpl user
qabort	jsr clrmenue
abort	pla
	pla
	jsr hatschon
	jmp finish
trau	jsr clrmenue
	ldx mousex
	ldy mousey
	lda mousevh
	rts
no1	dey
	dey
	sty strenght
	jsr get
	cmp #"\x03"
	beq abort
	jsr co1
	lda #0
	sta mensch
	tsx
	stx pstack
	sei
	jsr szug
	jsr co0
	ldx ergx
	ldy ergy
	lda ergvh
	rts
signal	lda #180
	sta s+1
	lda #70
	sta dudel+1
	lda #1
	sta beep
sign	cmp beep
	beq sign
	lda #100
	sta s+1
	lda #40
	sta dudel+1
	rts
behindern	lda anzhi
	asl
	tax
	lda hintab,x
	sta tmp4
	lda hintab+1,x
	sta tmp4+1
hi0	jsr gett
	tax
	bpl hi1
	inc feldtask
	jmp wartirq
hi1	beq hi3
	jsr gett
	sta tmp2
	jsr gett
	sta tmp2+1
	jsr gett
	sta tmp3
hi2	lda #1
	ldx tmp3
	ldy tmp2
	jsr setaxy
	inc tmp2
	lda tmp2
	cmp tmp2+1
	bcc hi2
	bcs hi0
hi3	jsr gett
	sta tmp2
	jsr gett
	sta tmp2+1
	jsr gett
	sta tmp3
hi4	lda #0
	ldy tmp3
	ldx tmp2
	jsr setaxy
	inc tmp2
	lda tmp2
	cmp tmp2+1
	bcc hi4
	bcs hi0
